<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Anti-aliasing and TrueType Fonts on OpenBSD</title>
<link rev="made" href="mailto:www@openbsd.org">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta name="resource-type" content="document">
<meta name="description"   content="the OpenBSD FAQ page">
<meta name="keywords"      content="openbsd,faq,antialiasing,anti-aliasing,truetype,fonts,X.org,XF4">
<meta name="distribution"  content="global">
<meta name="copyright"     content="This document copyright 2001-2008 by OpenBSD.">
</head>

<body bgcolor="#ffffff" text="#000000">
<a href="http://www.openbsd.org/"><img alt="[OpenBSD]" border="0"
  height=30 width=141 src="../images/smalltitle.gif"></a>

<h1>Anti-aliasing and TrueType Fonts on OpenBSD</h1>

<h3>Table of Contents</h3>
<ul>
<li><a href="truetype.html#xterm">xterm screenshot</a>
<li><a href="truetype.html#konqueror">Konqueror screenshot</a>
<li><a href="truetype.html#how">How does it work?</a>
<li><a href="truetype.html#work">What needs to be done to get it?</a>
<li><a href="truetype.html#applications">Which applications can use it?</a>
<li><a href="truetype.html#manualfonts">How can I add fonts manually?</a>
</ul>
<hr>

<a name="xterm"></a>
<h2>xterm screenshot</h2>
<a href="http://www.openbsd.org/cgi-bin/man.cgi?query=xterm&amp;sektion=1">xterm(1)</a>
with aliased and anti-aliased fonts side-by-side:
<div align="center"><img src="images/xterm_diff.jpg"
  alt="[Standard and anti-aliased xterm]"></div>

<a name="konqueror"></a>
<h2>Konqueror screenshot</h2>
Still not convinced?
Let's have a look at this.

<p>
The <a href="http://konqueror.kde.org/">Konqueror Web browser</a> with
aliased and anti-aliased fonts side-by-side:
<div align="center"><img src="images/konqueror_diff.jpg"
  alt="[Standard and anti-aliased Konqueror]"></div>

<a name="how"></a>
<h2>How does it work?</h2>
In order to support anti-aliased fonts, X has introduced in 2001 a new,
<i>client-side</i>, font rendering engine.   

The anti-aliasing calculations are done by
<a href="http://www.freetype.org/">FreeType</a>, a free font engine
that is used by a library called
<a href="http://www.openbsd.org/cgi-bin/man.cgi?query=Xft&amp;sektion=3">Xft(3)</a>,
the X FreeType interface.
The 
<a href="http://keithp.com/~keithp/talks/usenix2001/">Render</a>
extension provides the compositing operations that are needed to blend
the sup-pixel font shapes on the application background.
<p>
In addition X.Org uses the 
<a
href="http://www.openbsd.org/cgi-bin/man.cgi?query=fontconfig&amp;sektion=3">fontconfig(3)</a>
library to manage the
installed fonts, including their names and properties. 

<a name= "work"></a>
<h2>What needs to be done to get it?</h2>

Basically, nothing. OpenBSD ships X.org with the X Render extension
enabled in all video card drivers at 8 bit per pixel and more. 

<p>
You can verify that the Render extension is enabled by running:

<blockquote><pre>
$ <strong>/usr/X11R6/bin/xdpyinfo | grep RENDER</strong>
RENDER
</pre></blockquote>

<p>
In addition to the <b>Bitstream Vera</b> fonts family that ships
with OpenBSD, a collection of popular TrueType fonts has been compiled and is
available in the <a href="faq8.html#Ports">OpenBSD ports tree</a>, in
<tt>/usr/ports/x11/msttcorefonts</tt>.  They can be installed by doing
the following:

<blockquote><pre>
# <b>cd /usr/ports/x11/msttcorefonts</b>
# <b>make install</b>
</pre></blockquote>

<p>
The ports collection also include other TrueType fonts packages,
especially the <b>liberation</b> fonts that can be used as a
replacement for the Microsoft Web fonts above and are distributed with a
more acceptable license.

<a name= "applications"></a>
<h2>Which applications can use anti-aliased fonts?</h2>
Any application that interfaces with the Xft library can display
anti-aliased fonts. This includes QT 3.x (KDE 3.x) and GTK+2 (Gnome 2.x)
applications. Standard X programs that use this interface include
<a href="http://www.openbsd.org/cgi-bin/man.cgi?query=xterm&amp;sektion=1">xterm(1)</a>,
<a href="http://www.openbsd.org/cgi-bin/man.cgi?query=xclock&amp;sektion=1">xclock</a>,
and a few others.

<h3>xterm</h3>
<tt>xterm</tt> can be invoked with arguments that enable Xft rendering
of fonts:

<blockquote><pre>
$ <strong>xterm -fa 'Mono' -fs 14</strong>
</pre></blockquote>

These options are:
<blockquote><pre>
Option   Resource         Meaning
----------------------------------------
 -fa     XTerm*faceName   Font face name
 -fs     XTerm*faceSize   Font size
</pre></blockquote>

Alternatively, X resources can be used. They are by default placed in
<tt>$HOME/.Xdefaults</tt> and are controlled through the
<a href="http://www.openbsd.org/cgi-bin/man.cgi?query=xrdb&amp;sektion=1">xrdb(1)</a>
program.

<p>
Some TrueType fonts (such as Arial, Georgia, and Verdana, for example)
don't work well in <tt>xterm</tt>. This is because <tt>xterm</tt> uses
the maximum width of all characters in the specified font to display
each character. With a monospace font, the widths of all the characters
are the same, and everything works. With a proportional font, such as
the ones just mentioned, <tt>xterm</tt> fits each character into a cell
the size of the maximum width, creating unreadable large gaps between
characters.

<h3>QT 3.x/KDE 3.x applications</h3>
Applications that use QT 3.x, such as any KDE 3.5.x applications,
including Konqueror, use Xft rendering by default.

<h3>GTK+2 applications</h3>
GTK+2 applications also use Xft by default now.


<a name="manualfonts"></a>
<h2>How can I add fonts manually?</h2>

Adding a TrueType font &quot;to X&quot; requires registering the font
with both the fontconfig library and the X server
since both keep track of fonts separately.

<h3>Client-side font rendering system</h3>
Fonts installed as a package from the ports collection are registered
automatically to the fontconfig system.

Fontconfig uses the file
<tt>/etc/fonts/fonts.conf</tt> for its main system-wide configuration,
but since this file will be replaced on subsequent X upgrades,
<tt>/etc/fonts/local.conf</tt> should be used instead to manage
system-wide changes.

Fontconfig searches for fonts in all sub-directories of the
directories listed in <tt>/etc/fonts/fonts.conf</tt>. So there's no need to edit
this file when new fonts are added in those hierarchies. 

<p>
After a directory is added, the font cache for the directory will need
to be regenerated. The following command instructs fontconfig to rebuild
the font caches for all directories specified in its configuration:

<blockquote><pre>
# <b>/usr/X11R6/bin/fc-cache -v</b>
</pre></blockquote>

These changes will take effect in the current X session, so X itself
will not need to be restarted, but running applications will.

<p>
The <b>fc-list</b> command can be used to list all known fonts to the
system. Beware, this command outputs international fonts names encoded
in UTF-8. So it's better to run it in an UTF-8 capable terminal
emulation program, such as <b>uxterm</b>.



<h3>The server-side rendering system</h3>

Font paths (i.e., directories containing fonts) are managed either
directly by the X server, using <tt>/etc/X11/xorg.conf</tt>, or by a
separate program such as
<a href="http://www.openbsd.org/cgi-bin/man.cgi?query=xfs&amp;sektion=1">xfs(1)</a>.
To add a font, add the directory where it resides to
<tt>/etc/X11/xorg.conf</tt>:

<blockquote><pre>
Section "Files"
	FontPath	"/usr/X11R6/lib/X11/fonts/TTF/"
	FontPath	"<i>/usr/local/lib/X11/fonts/myfonts/</i>"
	...
EndSection
</pre></blockquote>

Or, if using <tt>xfs</tt>, add the directory to
<tt>/etc/X11/fs/config</tt>:

<blockquote><pre>
catalogue = /usr/X11R6/lib/X11/fonts/TTF/,
	    <i>/usr/local/lib/X11/fonts/myfonts/</i>
</pre></blockquote>

Next, the X server must be made aware of the font in that directory's
font index, i.e., the <tt>fonts.dir</tt> file. Traditionally, all
available sizes of a font were listed in the font index, generated by
the
<a href="http://www.openbsd.org/cgi-bin/man.cgi?query=mkfontdir&amp;sektion=1">mkfontdir(1)</a>
command. But since TrueType fonts can be scaled to any size, listing
every possible size is not required. Instead, scalable fonts are listed
in the file <tt>fonts.scale</tt> which is recognized by
<tt>mkfontdir</tt> when generating <tt>fonts.dir</tt> indexes.

<p>
To build a <tt>fonts.scale</tt> file, the
<a href="http://www.openbsd.org/cgi-bin/man.cgi?query=mkfontscale&amp;sektion=1">mkfontscale(1)</a>
program can be used:

<blockquote><pre>
# <b>cd <i>/usr/local/lib/X11/fonts/myfonts</i></b>
# <b>/usr/X11R6/bin/mkfontscale</b>
# <b>/usr/X11R6/bin/mkfontdir</b>
</pre></blockquote>

Finally, to apply the changes to the current X session, instead of
restarting X, the following command can be used to re-examine the
currently registered font paths for changes:

<blockquote><pre>
$ <b>xset fp rehash</b>
</pre></blockquote>

Or, if a new font path was added:

<blockquote><pre>
$ <b>xset +fp <i>/usr/local/lib/X11/fonts/myfonts</i></b>
</pre></blockquote>

If <tt>xfs</tt> is being used, the following command should be used instead:

<blockquote><pre>
# <b>pkill -HUP xfs</b>
</pre></blockquote>

<hr>
<a href="index.html"><img height="24" width="24" src="../images/back.gif"
  border="0" alt="[back]"></a>
<a href="mailto:www@openbsd.org">www@openbsd.org</a>
<br>
<small>$OpenBSD: truetype.html,v 1.19 2008/01/23 15:16:05 saad Exp $</small>
</body>
</html>
